package com.graduate.common.shiro;

import java.io.Serializable;
import java.util.Set;

import com.alibaba.fastjson.JSON;

import com.graduate.model.SysRole;
import com.graduate.model.SysUser;

/**
 * @description：自定义Authentication对象，使得Subject除了携带用户的登录名外还可以携带更多信息
 */
public class ShiroUser implements Serializable {
	private static final long serialVersionUID = -1373760761780840081L;

	private Long id;
	private final String loginName;
	private String name;
	private Set<String> urlSet;
	private Set<String> roles;
	private SysUser user;
	private SysRole role;
	
	
	public ShiroUser(String loginName, SysUser user,SysRole role) {
		this.loginName = loginName;
		this.user = user;
		
		this.role = role;
	}

	public ShiroUser(Long id, String loginName, String name, Set<String> urlSet) {
		this.id = id;
		this.loginName = loginName;
		this.name = name;
		this.urlSet = urlSet;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<String> getUrlSet() {
		return urlSet;
	}

	public void setUrlSet(Set<String> urlSet) {
		this.urlSet = urlSet;
	}

	public Set<String> getRoles() {
		return roles;
	}

	public void setRoles(Set<String> roles) {
		this.roles = roles;
	}

	public SysUser getUser() {
		return user;
	}

	public void setUser(SysUser user) {
		this.user = user;
	}

	

	public SysRole getRole() {
		return role;
	}

	public void setRole(SysRole role) {
		this.role = role;
	}

	
	public String getLoginName() {
		return loginName;
	}

	/**
	 * 本函数输出将作为默认的<shiro:principal/>输出.
	 */
	@Override
	public String toString() {

		this.user.setPwd(null);
		this.user.setSalt(null);
		/*
		 * User user = new User(); user.setUserCode(this.user.getUserCode());
		 * user.setUserName(this.user.getUserName());
		 * 
		 * Role role =new Role(); role.setCode(""+this.role.getCode());
		 * role.setName(this.role.getName()); role.setId(this.role.getId());
		 * 
		 * Org org = new Org(); org.setCode(this.org.getCode());
		 * org.setName(this.org.getName());
		 * org.setGrantCenterCode(this.org.getGrantCenterCode());
		 * 
		 * 
		 * ShiroUser sUser = new ShiroUser(this.user.getUserName(), user, org,
		 * role);
		 */
		return JSON.toJSONString(this);
	}

}